#pragma once
#include "CFrameworkElement.h"

class CBorder :
	public CFrameworkElement
{

private: 
	CBorder(CCoreServices * pCore);
private: 
	virtual ~CBorder();
public: 
	static HRESULT Create(CDependencyObject * * ppObject, CREATEPARAMETERS * pCreate);
	virtual XUINT32 GetTypeIndex() const;
	virtual XBOOL GetIsLayoutElement();
	virtual XINT32 CanHaveChildren();
	virtual XBOOL AreChildrenInLogicalTree();
	virtual HRESULT SetValue(CDependencyProperty * pdp, CValue * pValue);
	virtual HRESULT ClearValue(CDependencyProperty * pdp);
	virtual HRESULT AddChild(CUIElement * pChild);
	virtual CTransitionCollection * GetTransitionsForChildElementNoAddRef(CUIElement * pChild);
	virtual HRESULT GetBoundingRectangle(struct XRECTF_WH * pRect);
	static HRESULT Child(struct Xcp_IDependencyObject * pObject, XUINT32 cArgs, CValue * ppArgs, CValue * pResult);
	HRESULT SetChild(CUIElement * pChild);
	HRESULT GetChild(CUIElement * * ppChild);
	static void NWSetBackgroundBrushDirty(CDependencyObject * pTarget, enum DirtyFlags::Value flags);
	static void NWSetBorderBrushDirty(CDependencyObject * pTarget, enum DirtyFlags::Value flags);
	virtual XBOOL NWIsContentDirty();
	virtual XBOOL IsMaskDirty(HWShapeRealization * pHwShapeRealization);
	static void HelperDeflateRect(const struct XRECTF_WH & rect, const struct XRECTF_RB & thickness, struct XRECTF_WH & innerRect);
	virtual void GetIndependentlyAnimatedBrushes(CSolidColorBrush * * ppFillBrush, CSolidColorBrush * * ppStrokeBrush);
	XBOOL UseLayoutRoundingForBorderThickness();
	void GetLayoutRoundedThickness(struct XRECTF_RB & roundedThickness);
protected: 
	virtual HRESULT NWRenderPreChildrenEdgesVirtual(const struct SharedRenderParams & sharedRP, const struct NWRenderParams & nwRP, xvector<xref_ptr<CRasterizerEdgeStore> > & vecEdgeStores);
	virtual HRESULT MeasureOverride(struct XSIZEF availableSize, struct XSIZEF & desiredSize);
	virtual HRESULT ArrangeOverride(struct XSIZEF finalSize, struct XSIZEF & newFinalSize);
	virtual void NWCleanDirtyFlags();
	virtual void EnsureContentRenderDataVirtual(enum RenderWalkType oldType, enum RenderWalkType newType);
	virtual HRESULT GetBoundsForImageBrushVirtual(const CImageBrush * pImageBrush, struct XRECTF_WH * pBounds);
private: 
	static void HelperCollapseThickness(const struct XRECTF_RB & thickness, struct XSIZEF & size);
	XBOOL BorderExists() const;
	XBOOL BorderHasRendered() const;
	XBOOL BackgroundExists() const;
	XBOOL BackgroundHasRendered() const;
	XBOOL HasNonZeroCornerRadius();
	HRESULT GenerateEdgesCommon(XBOOL fRegenerateGeometry, XBOOL fBorderBrushChanged, XBOOL fBackgroundBrushChanged, const CMILMatrix * pTransform, CLayer * pLayer, xvector<xref_ptr<CRasterizerEdgeStore> > & vecEdgeStores);
	void ReleaseWalkSpecificResources(enum RenderWalkType lastRenderedType);
protected: 
	virtual HRESULT D2DEnsureResources(const struct D2DPrecomputeParams & cp, const CMILMatrix * pMyAccumulatedTransform);
	virtual HRESULT D2DComputeInnerBounds(struct XRECTF_RB * pInnerBounds);
	virtual HRESULT D2DPreChildrenRenderVirtual(const struct SharedRenderParams & sharedRP, const struct D2DRenderParams & d2dRP);
	virtual HRESULT D2DHitTestSelf(struct XPOINTF ptHit, CUIElement * * ppResult);
private: 
	HRESULT CreateBorderGeometriesAndBrushClipsCommon(const struct D2DPrecomputeParams & cp, const CMILMatrix * pMyAccumulatedTransform, struct AcceleratedBrushParams * pPALBackgroundBrushParams, struct AcceleratedBrushParams * pPALBorderBrushParams, struct IPALAcceleratedGeometry * * ppPALBackgroundGeometry, struct IPALAcceleratedGeometry * * ppPALBorderGeometry);
private: 
	HRESULT AcceleratedRenderCommon(const struct SharedRenderParams & sharedRP, const struct D2DRenderParams & d2dRP, struct IPALAcceleratedGeometry * pPALBackgroundGeometry, struct IPALAcceleratedBrush * pPALBackgroundBrush, struct AcceleratedBrushParams * pBackgroundBrushParams, struct IPALAcceleratedGeometry * pPALBorderGeometry, struct IPALAcceleratedBrush * pPALBorderBrush, struct AcceleratedBrushParams * pBorderBrushParams);
protected: 
	virtual HRESULT PreChildrenPrintVirtual(const struct SharedRenderParams & sharedPrintParams, const struct D2DPrecomputeParams & cp, const struct D2DRenderParams & printParams);
	virtual HRESULT GenerateContentBounds(struct XRECTF_RB * pBounds);
	virtual HRESULT HitTestLocalInternal(const HitTestPolygon & target, XBOOL * pHit);
	virtual HRESULT HitTestLocalInternal(const struct XPOINTF & target, XBOOL * pHit);
public: 
	XFLOAT m_eActualWidth;
	XFLOAT m_eActualHeight;
	struct XRECTF_RB m_borderThickness;

	struct XRECTF_RB m_padding;

	struct XRECTF_CR m_cornerRadius;

	CBrush * m_pBorderBrush;
	CBrush * m_pBackgroundBrush;
	CTransitionCollection * m_pChildTransitions;
private: 
	CRasterizerPath * m_pBorderPath;
	CRasterizerPath * m_pBackgroundPath;
	struct IPALAcceleratedGeometry * m_pPALBorderGeometry;
	struct IPALAcceleratedGeometry * m_pPALBackgroundGeometry;
	struct AcceleratedBrushParams * m_pPALBorderBrushParams;
	struct AcceleratedBrushParams * m_pPALBackgroundBrushParams;
	XBOOL m_fNWBorderBrushDirty:1;
	XBOOL m_fNWBackgroundBrushDirty:1;
};